package com.guoheng.hazard.sys.service.impl.entpr;

import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import com.guoheng.hazard.common.base.Result;
import com.guoheng.hazard.sys.model.dto.entpr.EntprProductionDeviceInsertDTO;
import com.guoheng.hazard.sys.model.dto.entpr.EntprProductionDeviceUpdateDTO;
import com.guoheng.hazard.sys.service.entpr.EntprProductionDeviceService;
import org.springframework.beans.BeanUtils;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;

import com.guoheng.hazard.sys.model.entity.entpr.EntprProductionDevice;
import com.guoheng.hazard.sys.mapper.entpr.EntprProductionDeviceMapper;

import java.util.List;

/**
 * 类功能描述:　EntprProductionDeviceServiceImpl
 *
 * @author fbl
 * @date 2019-41-13 9:41
 */
@Service
public class EntprProductionDeviceServiceImpl implements EntprProductionDeviceService {

    @Resource
    private EntprProductionDeviceMapper entprProductionDeviceMapper;


    @Override
    public Result getDevices(Long entprId, Integer pageNum, Integer pageSize) {
        PageHelper.startPage(pageNum, pageSize);
        List<EntprProductionDevice> devices = entprProductionDeviceMapper.getDevices(entprId);
        PageInfo<EntprProductionDevice> entprProductionDevicePageInfo = new PageInfo<>(devices);
        return Result.success(entprProductionDevicePageInfo);
    }

    @Override
    public Result updateDevice(EntprProductionDeviceUpdateDTO entprProductionDeviceUpdateDTO) {
        EntprProductionDevice entprProductionDevice = new EntprProductionDevice();
        BeanUtils.copyProperties(entprProductionDeviceUpdateDTO, entprProductionDevice);
        entprProductionDeviceMapper.updateDevice(entprProductionDevice);
        return Result.success();
    }

    @Override
    public Result insertDevice(EntprProductionDeviceInsertDTO entprProductionDeviceInsertDTO) {
        EntprProductionDevice entprProductionDevice = new EntprProductionDevice();
        BeanUtils.copyProperties(entprProductionDeviceInsertDTO, entprProductionDevice);
        entprProductionDeviceMapper.insertDevice(entprProductionDevice);
        return Result.success();
    }

    @Override
    public Result deleteDevice(Long id) {
        EntprProductionDevice entprProductionDevice = new EntprProductionDevice();
        entprProductionDevice.setId(id);
        entprProductionDevice.setDelFlag(true);
        entprProductionDeviceMapper.updateDevice(entprProductionDevice);
        return Result.success();
    }

    @Override
    public Result getDeviceById(Long id) {
        EntprProductionDevice deviceById = entprProductionDeviceMapper.getDeviceById(id);
        return Result.success(deviceById);
    }
}
